<?php

    /**
     * Install
     *
     * @package      Core
     * @subpackage   Installer_Adapter
     *
     * @license      GNU Lesser General Public Licence see LICENCE-LGPL file or http://www.gnu.org/licenses/lgpl.html
     */
	class Core_Installer_Adapter_Htaccess implements Core_Installer_Adapter_Interface
	{

	////////////////////////////////////////////////////////////////////////////
	//                                 Methods                                //
	////////////////////////////////////////////////////////////////////////////

        /**
         * Processes
         *
         * @param       array       $data
         * @return      string
         */
        public function process(array $data)
        {
            return
'php_value mbstring.internal_encoding	"UTF-8"
php_value mbstring.language 		 	"Neutral"
php_value mbstring.func_overload 		7

php_value date.timezone					"Europe/Paris"
php_value max_execution_time			0

RewriteEngine on
RewriteBase /

#
# Updater
#
RewriteCond %{REQUEST_URI}      ^'. $data['basePath'] .'([a-z]+)/updater/update\.php$
RewriteRule ^(.*)$              '. $data['basePath'] .'serum/updates/update.php?type=%1 [L]
RewriteCond %{REQUEST_URI}      ^'. $data['basePath'] .'([a-z]+)/updater/([a-z]+)\.([a-z]+)$
RewriteRule ^(.*)$              '. $data['basePath'] .'serum/updates/%2.%3 [L]

# Adds trailing slash
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI}      !(.*)/$
RewriteCond %{REQUEST_URI}      !\.html$
RewriteCond %{REQUEST_URI}      !\.php$
RewriteRule ^(.*)$              '. $data['basePath'] .'$1/ [L,R=301]

#
# Back Office
#

# Redirects to main controller
RewriteCond %{REQUEST_URI}  ^'. $data['basePath'] .'serum/
RewriteRule ^(.*)/$         '. $data['basePath'] .'project/serum/index.php?url=$1 [L]

RewriteCond %{REQUEST_URI}  ^'. $data['basePath'] .'serum/
RewriteCond %{REQUEST_URI}  /([a-z]+)\.php$
RewriteCond %1              !update$
RewriteCond %1              !validation$
RewriteCond %1              !webservice$
RewriteRule ^(.*)$         '. $data['basePath'] .'project/serum/%1.php?url=$1 [QSA,L]

#
# Front Office
#

# Redirects to main controller
RewriteCond %{REQUEST_URI}  !^'. $data['basePath'] .'project/
RewriteCond %{REQUEST_URI}  !^'. $data['basePath'] .'serum/
RewriteCond %{REQUEST_URI}  !^'. $data['basePath'] .'cron/
RewriteRule ^(.*)/$         '. $data['basePath'] .'project/index.php?url=$1 [L]

RewriteCond %{REQUEST_URI}  !^'. $data['basePath'] .'project/
RewriteCond %{REQUEST_URI}  !^'. $data['basePath'] .'serum/
RewriteCond %{REQUEST_URI}  !^'. $data['basePath'] .'cron/
RewriteRule ^(.*)$          '. $data['basePath'] .'project/index.php?url=$1 [L]';
        }
	}
